/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jl.tools.stkeditor.command;

import com.jl.tools.stkeditor.ISTKEditorFrm;

/**
 *
 * @author Administrator
 */
public class AppendCommand implements Command {

    private String preData;
    private final ISTKEditorFrm frm;

    public AppendCommand(ISTKEditorFrm frm2) {
        this.frm = frm2;
        preData = "";
    }

    @Override
    public void execute() {
        
        preData = frm.getCommandLinesText();
        
        int group = frm.getGroupNum();
        String groupStr = "" + group;
        if (group == 0) {
            groupStr = "none";
        }
        String code = frm.getCodeSchema();
        boolean with80 = frm.isWith80Checked();
        String tag = "";
        if (frm.isItemTagChecked()) {
            tag = "item";
        } else {
            tag = frm.getTag();
        }
        String text = frm.getInputText();
        
        String name = frm.getParamName();
        StringBuilder sb = new StringBuilder();
        sb.append("[G:").append(groupStr).append("/C:").append(code).append("/80:").append(with80).append("/T:").append(tag).append("/N:").append(name).append("]").append(text).append("\n");
        frm.appendOneLine(sb.toString());
    }

    @Override
    public void undo() {
        frm.setCommandLinesText(preData);
    }
}
